function animation(command, count){
	id1 = requestAnimationFrame(function(){
		animation(command,count);
	});
	
	if(ready == 'yes'){
		switch(command){
			case 'go':
					for(var i = 0; i < count; i++){
						switch(direction){
							case 0: go(0);break;
							case 1: go(1);break;
							case 2: go(2);break;
							case 3: go(3);break;
						}
					}	
				break;
			case 'tun lef': 
				
					rotate(-90);
					direction = (direction+3)%4;
				
				break;
			case 'tun rig': 
				
					rotate(90);
					direction = (direction+1)%4;
				
				break;
			case 'tun bac': 
				
					rotate(180);
					direction = (direction+2)%4;
				
				break;
			case 'tra lef':
				goLoop(count, 3);
				break;
			case 'tra top':
				goLoop(count, 0)
				break;
			case 'tra rig':
				goLoop(count, 1)
				break;
			case 'tra bot':
				goLoop(count, 2)
				break;
			case 'mov lef':
				
					direction = 3;
					rotate((270 - getAngle()%360));
					goLoop(count, 3)
				
				break;
			case 'mov top':
				
					direction = 0;
					rotate((0 - getAngle()));
					goLoop(count, 0)
				
				break;
			case 'mov rig':
				
					direction = 1;
					rotate((90 - getAngle()%360));
					goLoop(count, 1)
				
				break;
			case 'mov bot':
				
					direction = 2;
					rotate((180 - getAngle()%360));
					goLoop(count, 2)
				
				break;
		}
		cancelAnimationFrame(id1);
	}

}

function goLoop(number, direction){
	id2 = requestAnimationFrame(function(){
		goLoop(number, direction);
	});
	if(ready == 'yes'){
		for(var i = 0; i < number; i++){
			go(direction);
		}	
		cancelAnimationFrame(id2);
	}
}